package org.practice.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.stereotype.Service;

/**
 * 
 * @description: 显式调用Service
 * 
 */
@Service
public class ServiceProvider implements ApplicationContextAware{
	private static ApplicationContext ctx;
	public void setApplicationContext(ApplicationContext ctx) {
		ServiceProvider.ctx = ctx;
		// 销毁注册的勾子
		((AbstractApplicationContext) ctx).registerShutdownHook();
	}

	public static Object getService(String name) {
		return ctx.getBean(name);
	}

}
